package com.example.jobback.util;

import com.example.jobback.po.Manager;
import com.example.jobback.po.Recruiter;
import com.example.jobback.po.Seeker;

/**
 * @ClassName: TLUtil
 * @Description:使用线程存储个人信息工具类
 * @Author: lhb
 * @Date: 2025/5/10
 */
public class TLUtil {
    public static final ThreadLocal<Seeker> S = new ThreadLocal<>();
    public static final ThreadLocal<Recruiter> R = new ThreadLocal<>();
    public static final ThreadLocal<Manager> M = new ThreadLocal<>();
    public static final ThreadLocal<Long> USER_ID = new ThreadLocal<>();

    /**
     * @Description: 泛型 get 方法
     * @param threadLocal
     * @return T
     * @Author lhb
     * @CreateTime 2025/5/10 16:57
     */
    public static <T> T get(ThreadLocal<T> threadLocal) {
        return threadLocal.get();
    }

    /**
     * @Description: 泛型 set 方法
     * @param threadLocal
     * @param value
     * @return void
     * @Author lhb
     * @CreateTime 2025/5/10 16:57
     */
    public static <T> void set(ThreadLocal<T> threadLocal, T value) {
        threadLocal.set(value);
    }

    /**
     * @Description: 泛型 remove 方法
     * @param threadLocal
     * @return void
     * @Author lhb
     * @CreateTime 2025/5/10 16:57
     */
    public static <T> void remove(ThreadLocal<T> threadLocal) {
        threadLocal.remove();
    }

//        TLUtil.set(TLUtil.M,new Manager());
//        TLUtil.get(TLUtil.M);
//        TLUtil.remove(TLUtil.M);
//
//        TLUtil.set(TLUtil.USER_ID,1L);
//        TLUtil.get(TLUtil.USER_ID);
//        TLUtil.remove(TLUtil.USER_ID);
}
